﻿using System.Collections.Generic;
using Kaesoft.Hospedaje.Common;
using Kaesoft.Hospedaje.Entities;
using System;
using System.Windows;

namespace Kaesoft.Hospedaje.Common
{
    public class PanelErroresViewModel : ViewModelBase
    {
        private EntityList<ErrorMessage> _errores;
        private RelayCommand _closeCommand;

        public RelayCommand CloseCommand
        {
            get { return _closeCommand ?? (_closeCommand = new RelayCommand(Cerrar)); }
        }

        public Visibility LayoutVisibility
        {
            get
            {
                return Errores.Count > 0 ? Visibility.Visible : Visibility.Collapsed;
            }
        }

        public EntityList<ErrorMessage> Errores
        {
            get { return _errores ?? (_errores = new EntityList<ErrorMessage>()); }
            set
            {
                _errores = value;

                OnPropertyChanged("Errores");
                OnPropertyChanged("LayoutVisibility");
            }
        }

        void ErrorsCollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            OnPropertyChanged("LayoutVisibility");
        }

        public void Cerrar(object parameter)
        {
            Errores.Clear();
            OnPropertyChanged("LayoutVisibility");
        }
    }
}